<?php

/**
 * This is the model class for table "zy_tvshow".
 *
 * The followings are the available columns in table 'zy_tvshow':
 * @property integer $tv_id
 * @property string $tv_name
 * @property integer $is_limit
 * @property integer $sort
 * @property integer $is_delete
 * @property string $crate_time
 * @property string $crate_user
 * @property string $update_time
 * @property string $update_user
 */
class Tvshow extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Tvshow the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_tvshow';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('is_limit, sort, is_delete', 'numerical', 'integerOnly'=>true),
			array('tv_name', 'length', 'max'=>100),
			array('crate_user, update_user', 'length', 'max'=>50),
			array('crate_time, update_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('tv_id, tv_name, is_limit, sort, is_delete, crate_time, crate_user, update_time, update_user', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'tv_id' => Yii::t('base','TvId'),
			'tv_name' => Yii::t('base','Tv Name'),
			'is_limit' => Yii::t('base','Is Limit'),
			'sort' => Yii::t('base','Sort'),
			'is_delete' => 'Is Delete',
			'crate_time' => 'Crate Time',
			'crate_user' => 'Crate User',
			'update_time' => 'Update Time',
			'update_user' => 'Update User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('tv_id',$this->tv_id);
		$criteria->compare('tv_name',$this->tv_name,true);
		$criteria->compare('is_limit',$this->is_limit);
		$criteria->compare('sort',$this->sort);
		$criteria->compare('is_delete',0);
		$criteria->compare('crate_time',$this->crate_time,true);
		$criteria->compare('crate_user',$this->crate_user,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user',$this->update_user,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
						'defaultOrder'=>'sort ASC',
				),
		));
	}
	
	/**
	 * 转换中文，在列表显示
	 */
	public function getIsLimit($id){
		if($id == 0){
			return Yii::t('base','No');
		}else{
			return Yii::t('base','Yes');
		}
	}
}